|
|
|
|
|
|
|
Figure 31.11
When you add an HTML template to a WebClass,
you are presented with all of the HTML tags in
the template that can be connected to VB events. |
|
|
|
|
|
|
|
|
By way of comparison, think about what happens when you add a TextBox control to a standard Visual Basic form. You are in effect placing an object (the text box) in a container (the form). After you draw the text box, you can access all of its properties and events from the form's Code window. Similarly, Template1 is an object in your WebClass, much like the text box object on a form. |
|
|
|
|
|
|
|
|
The only difference between the events in a text box and those in a WebItem is that WebItem events are not automatically available from the Code window. You first have to go through the process of connecting HTML tags to program events. |
|
|
|
|
|
|
|
|
Try it with your sample program. Remember the hyperlink in the template to www.somewhere.com? When you imported the template, it was given the name Hyperlink1. Right-click it and choose Connect to Custom Event. A new event appears in the Designer window, also called Hyperlink1. Double-click the event name and the Code window opens in the Template1_HyperLink1 event. This new event is fired whenever a user clicks the hyperlink. Enter the following Response.Write statement so that the event procedure looks like this: |
|
|
|
|
|
|
|
|
Private Sub Template1_Hyperlink1()
Response.Write "<BR> You clicked me!<BR>"
End Sub |
|
|
|
|
|
|
|
|
Next, run the project. When the first page loads, change the filename at the end of the URL (something like Project1_WebClass1.ASP) to the template filename, TEST.HTM, and press Enter. The template page loads. If you choose View Source, you might notice that the hyperlink no longer points to www.somewhere.com but instead to an event in the WebClass. Click the hyperlink and you should see the words You Clicked Me displayed in the browser. You have just seen how a hyperlink in an HTML file can be connected to a Visual Basic program event. |
|
|
|
|
|